using System;
using Gj.Galaxy.Logic;
using UnityEngine;

namespace Gj
{
    public class UiPlugin : GamePlugin
    {
        private BasePage Page;

        public void OnInit(BaseGameSpace space)
        {
            Page = space.UiSpace.Page;
        }

        public void OnDestroy()
        {
        }

        public GameService[] GetRequireService()
        {
            return new GameService[] { DataService.single, OverlayService.single, MiniMapService.single };
        }

        public void OnUpdate()
        {
            // OverlayService.single.OnUpdate();
            // MiniMapService.single.OnUpdate();
        }

        public void LateUpdate()
        {
        }

        public void OnProcessRoom(object[] data)
        {
            // 处理进程
            foreach (object[] detail in data)
            {
                var key = (InfoKey)detail[(byte)DetailKey.Key];
                switch (key)
                {
                    case InfoKey.UiKey:
                        var info = detail[(byte)DetailKey.Value];
                        // 服务端直接下发json字符串
                        // 可以用于显示战斗信息
                        // 比如：第一阶段。。。。。
                        //      什么怪物出现啦！
                        Page.Send(SystemMessage.ServiceMessage, info);
                        break;
                }
            }
        }

        public void OnFinish(object result)
        {
        }

        public void OnSwitchArea()
        {
        }

        public void OnInstance(int targetIndex, byte relation, GamePlayer player, Vector3 position, bool isLocal,
            NetworkEsse master, Action<InitSyncListener> cb)
        {
        }

        public void OnDestroy(NetworkEsse instance, GamePlayer player)
        {
        }

        public void OnBroadcast(GamePlayer player, byte code, Vector3 position, StreamReader reader)
        {
        }

        public void OnEnterRoom(bool first)
        {
        }

        public void OnPlayerJoin(GamePlayer player)
        {
        }

        public void OnPlayerLeave(GamePlayer player)
        {
        }

        public void OnPlayerRejoin(GamePlayer player)
        {
        }

        public void OnFailConnect()
        {
        }

        public void OnReady()
        {
        }

        public void OnReadyPlayer(GamePlayer player)
        {
        }

        public void OnStart()
        {
        }

        public void OnReadyAll()
        {
        }

        public void OnInitGame()
        {
        }

        public void OnTimeMove(int startTime, int endTime, StreamReader reader, Vector3[] positions, int index,
            Vector3 middlePosition)
        {
        }

        public void OnTimeProcess(int startTime, int endTime, StreamReader reader)
        {
        }
    }
}